 print "\n ~ Loading Files...\n";
print "\t + evalcommands.pl...";
require("./other/evalcommands.pl");
print "\n\t + send.pl...";
require("./other/send.pl");
print "\n\t + staff.pl...";
require("./other/staff.pl");
print "\n\t + cmd_owner.pl...";
require("./commands/cmd_owner.pl");
print "\n\t + cmd_admin.pl...";
require("./commands/cmd_admin.pl");
print "\n\t + cmd_smod.pl...";
require("./commands/cmd_smod.pl");
print "\n\t + cmd_mod.pl...";
require("./commands/cmd_mod.pl");
print "\n\t + cmd_public.pl...";
require("./commands/cmd_public.pl");
print "\n\t + cmd_guest.pl...";
require("./commands/cmd_guest.pl");
print "\n\t + cmd_chat.pl...";
require("./commands/cmd_chat.pl");

print "\n\n ~ Connecting...\n\n";
# Load up the config
$config = do("$confdir/settings.dump");
$users = do("$confdir/users.dump");
# Do some MSN Object stuff
$msn = new MSN('Handle' => $config->{passport}, 'Password' => $config->{password});
$msn->setHandler('Connected' => \&Connected);
$msn->setHandler('Message' => \&Message);
$msn->setHandler('RoomUpdated' => \&WelcomeMessage);

# Message style
$msn->setMessageStyle(Color => $config->{style}->{Color}, Effect => $config->{style}->{Effect}, Font =>$config->{style}->{Font});

# SHORT VARIABLE
# Command prefix
$p = $config->{prefix};

$msn->connect();
$config->{online} = 1;
while($config->{online}) {
  $msn->do_one_loop;
}

sub Connected {
  my $self = shift;
  print( " ~ Connected Successfully!\n\n" );
  $msn->setDisplayPicture($config->{dispic});
}

sub Message {
  my ($self, $user, $name, $msg, %style) = @_;
  $email = $user;
  if (exists $session->{$email}) {
    $user = $session->{$email};
  }
  else {
    $user = "guest";
  }
  &command($self, $user, $name, $email, $msg, %style);
  local $Data::Dumper::Varname = "Configuration";
  open (FILE, ">$confdir/settings.dump");
  print FILE Dumper($config);
  close FILE;
  
  local $Data::Dumper::Varname = "Users";
  open (FILE, ">$confdir/users.dump");
  print FILE Dumper($users);
  close FILE;
  
  print " ~ $user:\n\t + $msg\n\n";
}

sub WelcomeMessage {
  my ($self, $user, $name) = @_;
    if (exists $session->{$email}) {
    $user = $session->{$email};
  }
  else {
    $user = "guest";
  }
  if ($user eq 'guest') {
    $self->sendMessage("Type !login <username> <password> to login, or !register <username> <password> to register.");
  }
  else {
    $self->sendMessage("Hey, $user!");
  }
}